package com.doudou.casebook;

import androidx.appcompat.app.AppCompatActivity;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.DrawableImageViewTarget;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.doudou.casebook.adapter.AccountAdapter;
import com.doudou.casebook.db.AccountBean;
import com.doudou.casebook.db.DBManager;

import java.util.ArrayList;
import java.util.List;

public class SearchActivity extends AppCompatActivity {
    ListView searchLv;
    EditText searchEt;
    TextView emptyTv;
    List<AccountBean> mDatas;//
    AccountAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        initView();
        mDatas = new ArrayList<>();
        adapter = new AccountAdapter(this,mDatas);
        searchLv.setAdapter(adapter);
        searchLv.setEmptyView(emptyTv);//设置无数据显示的控件

// 在合适的位置获取 ImageView 实例
        ImageView imageView = findViewById(R.id.search_lv_empty_iv);

// 使用 Glide 加载和显示 GIF 图片
        RequestOptions options = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.DATA); // 禁用磁盘缓存，以确保刷新 GIF 图片

        Glide.with(this)
                .asGif()
                .load(R.drawable.baby_pazou)
                .apply(options)
                .into(imageView);



    }

    public void onClick(View view) {
        if(view.getId()==R.id.search_iv_back){
            finish();
        }
        if(view.getId()==R.id.search_iv_search){
            String msg = searchEt.getText().toString().trim();
            if (TextUtils.isEmpty(msg)) {
                Toast.makeText(this, "输入内容不能为空!", Toast.LENGTH_SHORT).show();
                return;
            }
            // 开始搜索
            List<AccountBean> list = DBManager.getAccountListBybeizhu(msg);
            mDatas.clear();
            mDatas.addAll(list);
            adapter.notifyDataSetChanged();
        }
    }

    private void initView(){
        searchEt=findViewById(R.id.search_et);
        searchLv=findViewById(R.id.search_lv);
        emptyTv=findViewById(R.id.search_lv_empty);
    }
}